import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-09-26
 * Time: 19:01
 */
class Solution {
    public List<List<Integer>> generate(int numRows) {

        List<Integer> list = new ArrayList<>();

        List<List<Integer>> ret = new ArrayList<>();

        list.add(1);

        ret.add(list);

        for(int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);

            List<Integer> preRow = ret.get(i - 1);

            for(int j = 1; j < i ; j++) {

                int val = preRow.get(j - 1) + preRow.get(j);

                curRow.add(val);
            }
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }
}

public class Test1 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.generate(4);
    }
}
